import { createStore, applyMiddleware } from 'redux';
import { thunk } from 'redux-thunk';

const initialState = {
    count: 0
    , message: ''
    , users: []
    , tasks: []
    , currentUser: null
};

function rootReducer(state = initialState, action) {
    switch (action.type) {
        case 'INCREMENT':
            return { ...state, count: state.count + 1 };
        case 'SET_MESSAGE':
            return { ...state, message: action.payload };
        case 'SET_USERS':
            return { ...state, users: action.payload };
        case 'SET_TASKS':
            return {...state,tasks:action.payload};
        case 'ADD_TASK':
            return {...state,tasks:[...state.tasks,action.payload]};
        case 'SET_CURRENT_USER':
            return {...state,currentUser:action.payload};
        default:
            return state;
    }
}

const store = createStore(rootReducer,applyMiddleware(thunk)) //
export default store;
